package io.renren.modules.vastFinance.controller;

import io.renren.common.utils.Result;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.vastFinance.entity.BankCard;
import io.renren.modules.vastFinance.entity.BankcardEntity;
import io.renren.modules.vastFinance.service.BankcardService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 银行卡表
 *
 * @author syh
 * @email sunlightcs@gmail.com
 * @date 2022-05-19 09:40:52
 */
@RestController
@RequestMapping("crud/bankcard")
public class BankcardController {
    @Autowired
    private BankcardService bankcardService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("crud:bankcard:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bankcardService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{cardId}")
    @RequiresPermissions("crud:bankcard:info")
    public R info(@PathVariable("cardId") Integer cardId){
		BankcardEntity bankcard = bankcardService.getById(cardId);

        return R.ok().put("bankcard", bankcard);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("crud:bankcard:save")
    public R save(@RequestBody BankcardEntity bankcard){
		bankcardService.save(bankcard);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("crud:bankcard:update")
    public R update(@RequestBody BankcardEntity bankcard){
		bankcardService.updateById(bankcard);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("crud:bankcard:delete")
    public R delete(@RequestBody Integer[] cardIds){
		bankcardService.removeByIds(Arrays.asList(cardIds));

        return R.ok();
    }

    /**
     * 银行卡验证
     * @param bankCard
     * @return
     */
    @RequestMapping("verifyBankCard")
    public Result verifyBankCard(@RequestBody BankCard bankCard, @RequestParam("userId") Integer userId){
        return bankcardService.verifyBankCard(bankCard,userId);
    }

    /**
     * 获取银行卡号
     * @param cardId
     * @return
     */
    @RequestMapping("getBankCard")
    public Result<BankcardEntity> getBankCard(@RequestParam("cardId") Integer cardId){
        return bankcardService.getBankCard(cardId);
    }

}
